package com.hq.fxh.HttpApi;

import com.hq.fxh.Modle.GetDayStatisticalResultRes;
import com.hq.fxh.Modle.GetEnterpriseRankRes;
import com.hq.fxh.Modle.GetEnterpriseReportRes;
import com.hq.fxh.Modle.GetEntertainmentListRes;
import com.hq.fxh.Modle.GetWeekStatisticalResultRes;
import com.hq.fxh.Modle.KanTieListModle;
import com.hq.fxh.Modle.PlateListModle;
import com.hq.fxh.Modle.PlateSoreModle;
import com.hq.fxh.Modle.RequstReq;
import com.hq.fxh.Modle.SelectByCategoryIdRes;
import com.hq.fxh.Modle.UploadImgRes;
import com.hq.fxh.No5_User.MyModle.Model.CommonRes;
import com.hq.fxh.No5_User.MyModle.Model.GetAdvertByUidRes;
import com.hq.fxh.No5_User.MyModle.Model.GetHomePageByUidRes;
import com.hq.fxh.No5_User.MyModle.Model.GetWebUrlRes;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/8/15
 * @Email xlwenhao1858@sina.com
 */


public class UserServiceImpl {
    public static UserService userService;
    static String baseV5Url = "http://ledianduo.com:8088/v5/api.asmx/";
    static String GetPostCagetoryUrl = baseV5Url + "GetPostCagetory";
    static String insertPlateUrl = baseV5Url + "InsertPost";
    static String getPlateListUrl = baseV5Url + "GetPostByCategory";
    static String getKanTieListUrl = baseV5Url + "GetPostList";
    static String FollowerCategoryUrl = baseV5Url + "FollowerCategory";


    public static void getWeekStatisticalResult(String uid, Subscriber<GetWeekStatisticalResultRes> subscriber) {
        userService.getWeekStatisticalResult(uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public static void getDayStatisticalResult(String uid, String date, int sort, int page, int pageSize, Subscriber<GetDayStatisticalResultRes> subscriber) {
        userService.getDayStatisticalResult(uid, date, sort, page, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    //【企业数据统计】[uid]
    public static void getEnterpriseReport(String uid, Subscriber<GetEnterpriseReportRes> subscriber) {
        userService.getEnterpriseReport(uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }


    public static void getPicSubjectList(int page, int pageSize, int type, Subscriber<GetEntertainmentListRes> subscriber) {
        userService.getPicSubjectList(page, pageSize, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public static void getEntertainmentList(int page, int pageSize, int type, Subscriber<GetEntertainmentListRes> subscriber) {
        userService.getEntertainmentList(page, pageSize, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public static void getPlateSore(Callback<PlateSoreModle> callback) {
        Call<PlateSoreModle> responseBodyCall = userService.GetPlateSortList(GetPostCagetoryUrl);
        responseBodyCall.enqueue(callback);


    }

    public static void uploadPlate(String content, Callback<RequstReq> callback) {

        Call<RequstReq> responseBodyCall = userService.uploadPlate(insertPlateUrl, content);
        responseBodyCall.enqueue(callback);
    }

    /**
     * 上传图片
     *
     * @param subscriber
     */
    public static void uploadImg(String key, String serializedData, String type, Subscriber<UploadImgRes> subscriber) {
        userService.uploadImg(key, serializedData, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);

    }

    public static void getPlateList(int category_id, int type, int page, int page_size, Callback<PlateListModle> callback) {
        Call<PlateListModle> plateList = userService.getPlateList(getPlateListUrl, category_id, type, page, page_size);
        plateList.enqueue(callback);
    }

    /**
     * 根据文章栏目ID查询文章,返回列表
     *
     * @param subscriber
     */
    public static void selectByCategoryId(String categoryId, int pageNum, int PageSize, Subscriber<SelectByCategoryIdRes> subscriber) {
        userService.selectByCategoryId("1001", pageNum, PageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public static void GetKanTieListUrl(int type, int pageNum, int PageSize, Callback<KanTieListModle> callback) {
        Call<KanTieListModle> kanTieList = userService.getKanTieList(getKanTieListUrl, type, pageNum, PageSize);
        kanTieList.enqueue(callback);

    }


    public static void getEnterpriseRank(String uid, int sort, int type, int page, int pageSize, Subscriber<GetEnterpriseRankRes> subscriber) {
        userService.getEnterpriseRank(uid, sort, type, page, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }


    /**
     * 获取Web页面地址
     *
     * @param subscriber
     */
    public static void getWebUrl(String url, Subscriber<GetWebUrlRes> subscriber) {
        userService.getWebUrl(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    /**
     * 获取形象空间所有信息
     *
     * @param subscriber
     */
    public static void getHomePageByUid(String uid, Subscriber<GetHomePageByUidRes> subscriber) {
        userService.getHomePageByUid(uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    /**
     * 更新形象空间
     *
     * @param subscriber
     */
    public static void updateHomePageInfo(String uid, int type, String json, Subscriber<CommonRes> subscriber) {
        userService.updateHomePageInfo(uid, type, json)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public static void getAdTemp(String uid, Subscriber<GetAdvertByUidRes> subscriber) {
        userService.getAdTemp(uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public static void updateAdvert(String uid, String json, Subscriber<CommonRes> subscriber) {
        userService.updateAdvert(uid, json)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(subscriber);
    }

    public static void followerPlater(int type, int id, Callback<RequstReq> subscriber) {
        Call<RequstReq> requstReqCall = userService.followerPlate(FollowerCategoryUrl, type, id);
        requstReqCall.enqueue(subscriber);

    }

    ;


}
